# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgbase=api-dnsdumpster
pkgname=('python2-api-dnsdumpster' 'python-api-dnsdumpster')
pkgver=79.0f8ba2b
pkgrel=2
groups=('blackarch' 'blackarch-recon' 'blackarch-scanner')
pkgdesc='Unofficial Python API for http://dnsdumpster.com/.'
arch=('any')
url='https://github.com/PaulSec/API-dnsdumpster.com'
license=('custom:unknown')
makedepends=('git' 'python2-setuptools' 'python-setuptools')
source=("$pkgbase::git+https://github.com/PaulSec/API-dnsdumpster.com.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgbase

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

prepare() {
  cp -a "$pkgbase"{,-2}
}

build() {
  cd "$pkgbase-2"

  python2 setup.py build

  cd "$srcdir/$pkgbase"

  python setup.py build
}

package_python2-api-dnsdumpster() {
  depends=('python' 'python-beautifulsoup4' 'python-requests')

  cd "$pkgbase-2"

  python2 setup.py install --root="$pkgdir" --prefix=/usr -O1 --skip-build

  install -Dm 644 -t "$pkgdir/usr/share/${pkgname[0]}/" README.md

  find "$pkgdir" -type f -iname '*.pyc' -exec rm {} \;
}

package_python-api-dnsdumpster() {
  depends=('python' 'python-beautifulsoup4' 'python-requests')

  cd $pkgbase

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgbase"

  python setup.py install --root="$pkgdir" --prefix=/usr -O1 --skip-build

  install -Dm 644 -t "$pkgdir/usr/share/${pkgname[1]}/" README.md

  rm README.md

  cp -a dnsdumpster/* "$pkgdir/usr/share/$pkgbase/"

  cat > "$pkgdir/usr/bin/$pkgbase" << EOF
#!/bin/sh
exec python /usr/share/$pkgbase/API_example.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgbase"

  find "$pkgdir" -type f -iname '*.pyc' -exec rm {} \;
}

